<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色管理 - 酒店管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        /* 树形结构样式 */
        .tree-view ul {
            list-style-type: none;
            padding-left: 1.5rem;
        }
        .tree-view li {
            margin: 0.5rem 0;
        }
        .tree-node {
            display: flex;
            align-items: center;
        }
        .tree-toggle {
            cursor: pointer;
            width: 1.5rem;
            text-align: center;
        }
        .tree-label {
            cursor: pointer;
            flex: 1;
            display: flex;
            align-items: center;
        }
        .tree-checkbox {
            margin-right: 0.5rem;
        }
        /* 自定义复选框样式 */
        .custom-checkbox {
            position: relative;
            display: inline-block;
            width: 16px;
            height: 16px;
            margin-right: 8px;
        }
        .custom-checkbox input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        .checkmark {
            position: absolute;
            top: 0;
            left: 0;
            width: 16px;
            height: 16px;
            background-color: #fff;
            border: 1px solid #d1d5db;
            border-radius: 3px;
        }
        .custom-checkbox input:checked ~ .checkmark {
            background-color: #4f46e5;
            border-color: #4f46e5;
        }
        .custom-checkbox input:indeterminate ~ .checkmark {
            background-color: #e5e7eb;
            border-color: #4f46e5;
        }
        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }
        .custom-checkbox input:checked ~ .checkmark:after {
            display: block;
            left: 5px;
            top: 2px;
            width: 5px;
            height: 10px;
            border: solid white;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }
        .custom-checkbox input:indeterminate ~ .checkmark:after {
            display: block;
            left: 3px;
            top: 7px;
            width: 10px;
            height: 2px;
            background-color: #4f46e5;
        }
    </style>
</head>
<body class="bg-gray-100">
    <!-- 页面内容与原来相同，只修改分配权限模态框 -->
    
    <!-- 分配权限模态框 - 树形结构版本 -->
    <div id="assignPermissionModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-2/3 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">分配权限 - 系统管理员</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('assignPermissionModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2">
                <div class="mb-4">
                    <div class="flex justify-between items-center mb-2">
                        <h4 class="text-md font-medium text-gray-700">权限列表</h4>
                        <div>
                            <button type="button" class="text-indigo-600 hover:text-indigo-900 text-sm mr-2" id="expandAllBtn">
                                展开全部
                            </button>
                            <button type="button" class="text-indigo-600 hover:text-indigo-900 text-sm mr-2" id="collapseAllBtn">
                                收起全部
                            </button>
                            <button type="button" class="text-indigo-600 hover:text-indigo-900 text-sm mr-2" id="selectAllBtn">
                                全选
                            </button>
                            <button type="button" class="text-indigo-600 hover:text-indigo-900 text-sm" id="deselectAllBtn">
                                取消全选
                            </button>
                        </div>
                    </div>
                    
                    <!-- 搜索权限 -->
                    <div class="mb-4">
                        <div class="relative">
                            <input type="text" id="permissionSearch" class="w-full pl-10 pr-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" placeholder="搜索权限...">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-search text-gray-400"></i>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 树形权限列表 -->
                    <div class="border rounded-md p-4 max-h-96 overflow-y-auto tree-view">
                        <ul id="permissionTree">
                            <!-- 系统管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="system-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox parent-checkbox" data-id="system">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span class="font-medium">系统管理</span>
                                    </label>
                                </div>
                                <ul id="system-children">
                                    <!-- 用户管理 -->
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle" data-target="user-children">
                                                <i class="fas fa-chevron-down"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox child-checkbox" data-id="user" data-parent="system">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>用户管理</span>
                                            </label>
                                        </div>
                                        <ul id="user-children">
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-view" data-parent="user">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>查看用户</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-add" data-parent="user">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>添加用户</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-edit" data-parent="user">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>编辑用户</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-delete" data-parent="user">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>删除用户</span>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                    
                                    <!-- 角色管理 -->
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle" data-target="role-children">
                                                <i class="fas fa-chevron-down"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox child-checkbox" data-id="role" data-parent="system">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>角色管理</span>
                                            </label>
                                        </div>
                                        <ul id="role-children">
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-view" data-parent="role">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>查看角色</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-add" data-parent="role">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>添加角色</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-edit" data-parent="role">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>编辑角色</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-delete" data-parent="role">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>删除角色</span>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                    
                                    <!-- 权限管理 -->
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle" data-target="permission-children">
                                                <i class="fas fa-chevron-down"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox child-checkbox" data-id="permission" data-parent="system">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>权限管理</span>
                                            </label>
                                        </div>
                                        <ul id="permission-children">
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-view" data-parent="permission">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>查看权限</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-assign" data-parent="permission">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>分配权限</span>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                            
                            <!-- 酒店管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="hotel-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox parent-checkbox" data-id="hotel">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span class="font-medium">酒店管理</span>
                                    </label>
                                </div>
                                <ul id="hotel-children">
                                    <!-- 酒店信息 -->
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle" data-target="hotel-info-children">
                                                <i class="fas fa-chevron-down"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox child-checkbox" data-id="hotel-info" data-parent="hotel">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>酒店信息</span>
                                            </label>
                                        </div>
                                        <ul id="hotel-info-children">
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-view" data-parent="hotel-info">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>查看酒店</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-add" data-parent="hotel-info">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>添加酒店</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-edit" data-parent="hotel-info">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>编辑酒店</span>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                    
                                    <!-- 房间管理 -->
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle" data-target="room-children">
                                                <i class="fas fa-chevron-down"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox child-checkbox" data-id="room" data-parent="hotel">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>房间管理</span>
                                            </label>
                                        </div>
                                        <ul id="room-children">
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="room-view" data-parent="room">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>查看房间</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="room-add" data-parent="room">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>添加房间</span>
                                                    </label>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="tree-node">
                                                    <span class="tree-toggle invisible">
                                                        <i class="fas fa-chevron-right"></i>
                                                    </span>
                                                    <label class="tree-label">
                                                        <span class="custom-checkbox">
                                                            <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="room-edit" data-parent="room">
                                                            <span class="checkmark"></span>
                                                        </span>
                                                        <span>编辑房间</span>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                            
                            <!-- 预订管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="booking-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox parent-checkbox" data-id="booking">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span class="font-medium">预订管理</span>
                                    </label>
                                </div>
                                <ul id="booking-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="booking-view" data-parent="booking">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看预订</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="booking-create" data-parent="booking">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>创建预订</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="booking-cancel" data-parent="booking">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>取消预订</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="flex justify-end mt-6">
                    <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('assignPermissionModal')">
                        取消
                    </button>
                    <button type="button" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded" id="savePermissionsBtn">
                        保存
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- 页面其他内容 -->
    <div class="container mx-auto px-4 py-8">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold text-gray-900">角色管理</h1>
            <button class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded" onclick="openModal('addRoleModal')">
                <i class="fas fa-plus mr-2"></i>添加角色
            </button>
        </div>

        <!-- 搜索区域 -->
        <div class="bg-white rounded-lg shadow-sm p-4 mb-6">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">角色名称</label>
                    <input type="text" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入角色名称">
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">角色编码</label>
                    <input type="text" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入角色编码">
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                    <select class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                        <option value="">全部</option>
                        <option value="1">启用</option>
                        <option value="0">禁用</option>
                    </select>
                </div>
            </div>
            <div class="flex justify-end mt-4">
                <button class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2">
                    重置
                </button>
                <button class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                    搜索
                </button>
            </div>
        </div>

        <!-- 角色列表 -->
        <div class="bg-white rounded-lg shadow overflow-hidden">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            角色名称
                        </th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            角色编码
                        </th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            描述
                        </th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            状态
                        </th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            创建时间
                        </th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    <tr>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">系统管理员</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-900">ADMIN</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">系统管理员，拥有所有权限</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                启用
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                            2023-05-10 10:30:00
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('assignPermissionModal')">分配权限</button>
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('editRoleModal')">编辑</button>
                            <button class="text-red-600 hover:text-red-900">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">酒店经理</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-900">MANAGER</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">酒店经理，管理酒店日常运营</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                启用
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                            2023-05-12 14:20:00
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('assignPermissionModal')">分配权限</button>
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('editRoleModal')">编辑</button>
                            <button class="text-red-600 hover:text-red-900">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">前台接待</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-900">RECEPTIONIST</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">前台接待，负责客户接待和预订管理</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                启用
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                            2023-05-15 09:10:00
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('assignPermissionModal')">分配权限</button>
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3" onclick="openModal('editRoleModal')">编辑</button>
                            <button class="text-red-600 hover:text-red-900">删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <!-- 分页 -->
            <div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
                <div class="flex-1 flex justify-between sm:hidden">
                    <a href="#" class="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
                        上一页
                    </a>
                    <a href="#" class="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
                        下一页
                    </a>
                </div>
                <div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
                    <div>
                        <p class="text-sm text-gray-700">
                            显示第 <span class="font-medium">1</span> 到 <span class="font-medium">3</span> 条，共 <span class="font-medium">12</span> 条记录
                        </p>
                    </div>
                    <div>
                        <nav class="relative z-0 inline-flex rounded-md shadow-sm -space-x-px" aria-label="Pagination">
                            <a href="#" class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
                                <span class="sr-only">上一页</span>
                                <i class="fas fa-chevron-left"></i>
                            </a>
                            <a href="#" aria-current="page" class="z-10 bg-indigo-50 border-indigo-500 text-indigo-600 relative inline-flex items-center px-4 py-2 border text-sm font-medium">
                                1
                            </a>
                            <a href="#" class="bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium">
                                2
                            </a>
                            <a href="#" class="bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium">
                                3
                            </a>
                            <a href="#" class="bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium">
                                4
                            </a>
                            <a href="#" class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
                                <span class="sr-only">下一页</span>
                                <i class="fas fa-chevron-right"></i>
                            </a>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 添加角色模态框 -->
    <div id="addRoleModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">添加角色</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('addRoleModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2">
                <form>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="roleName">角色名称</label>
                        <input type="text" id="roleName" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入角色名称">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="roleCode">角色编码</label>
                        <input type="text" id="roleCode" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入角色编码">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="roleDesc">角色描述</label>
                        <textarea id="roleDesc" rows="3" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入角色描述"></textarea>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <div class="flex items-center">
                            <input type="radio" id="statusEnable" name="status" value="1" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" checked>
                            <label for="statusEnable" class="ml-2 block text-sm text-gray-700">启用</label>
                            <input type="radio" id="statusDisable" name="status" value="0" class="ml-6 focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300">
                            <label for="statusDisable" class="ml-2 block text-sm text-gray-700">禁用</label>
                        </div>
                    </div>
                    <div class="flex justify-end mt-6">
                        <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('addRoleModal')">
                            取消
                        </button>
                        <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                            确定
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- 编辑角色模态框 -->
    <div id="editRoleModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">编辑角色</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('editRoleModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2">
                <form>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editRoleName">角色名称</label>
                        <input type="text" id="editRoleName" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" value="系统管理员">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editRoleCode">角色编码</label>
                        <input type="text" id="editRoleCode" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" value="ADMIN">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editRoleDesc">角色描述</label>
                        <textarea id="editRoleDesc" rows="3" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">系统管理员，拥有所有权限</textarea>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <div class="flex items-center">
                            <input type="radio" id="editStatusEnable" name="editStatus" value="1" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" checked>
                            <label for="editStatusEnable" class="ml-2 block text-sm text-gray-700">启用</label>
                            <input type="radio" id="editStatusDisable" name="editStatus" value="0" class="ml-6 focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300">
                            <label for="editStatusDisable" class="ml-2 block text-sm text-gray-700">禁用</label>
                        </div>
                    </div>
                    <div class="flex justify-end mt-6">
                        <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('editRoleModal')">
                            取消
                        </button>
                        <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                            确定
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- JavaScript 代码 -->
    <script>
        // 打开模态框
        function openModal(modalId) {
            document.getElementById(modalId).classList.remove('hidden');
            document.body.style.overflow = 'hidden';
        }

        // 关闭模态框
        function closeModal(modalId) {
            document.getElementById(modalId).classList.add('hidden');
            document.body.style.overflow = 'auto';
        }

        // 树形结构展开/折叠
        document.addEventListener('DOMContentLoaded', function() {
            const toggles = document.querySelectorAll('.tree-toggle:not(.invisible)');
            toggles.forEach(toggle => {
                toggle.addEventListener('click', function() {
                    const targetId = this.getAttribute('data-target');
                    const targetElement = document.getElementById(targetId);
                    const icon = this.querySelector('i');
                    
                    if (targetElement.style.display === 'none') {
                        targetElement.style.display = 'block';
                        icon.classList.remove('fa-chevron-right');
                        icon.classList.add('fa-chevron-down');
                    } else {
                        targetElement.style.display = 'none';
                        icon.classList.remove('fa-chevron-down');
                        icon.classList.add('fa-chevron-right');
                    }
                });
            });

            // 处理复选框级联选择
            const checkboxes = document.querySelectorAll('.tree-checkbox');
            checkboxes.forEach(checkbox => {
                checkbox.addEventListener('change', function() {
                    const isChecked = this.checked;
                    const id = this.getAttribute('data-id');
                    
                    // 如果是父级复选框，选中/取消选中所有子级
                    if (this.classList.contains('parent-checkbox')) {
                        const childCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${id}"]`);
                        childCheckboxes.forEach(childCheckbox => {
                            childCheckbox.checked = isChecked;
                            
                            // 处理孙级复选框
                            const childId = childCheckbox.getAttribute('data-id');
                            const grandChildCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${childId}"]`);
                            grandChildCheckboxes.forEach(grandChildCheckbox => {
                                grandChildCheckbox.checked = isChecked;
                            });
                        });
                    }
                    
                    // 如果是子级复选框，更新父级复选框状态
                    if (this.classList.contains('child-checkbox') || this.classList.contains('leaf-checkbox')) {
                        const parentId = this.getAttribute('data-parent');
                        if (parentId) {
                            const parentCheckbox = document.querySelector(`.tree-checkbox[data-id="${parentId}"]`);
                            if (parentCheckbox) {
                                // 检查所有同级复选框是否都被选中
                                const siblingCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${parentId}"]`);
                                const allChecked = Array.from(siblingCheckboxes).every(cb => cb.checked);
                                const anyChecked = Array.from(siblingCheckboxes).some(cb => cb.checked);
                                
                                parentCheckbox.checked = allChecked;
                                
                                // 如果是子级复选框，还需要处理叶子节点
                                if (this.classList.contains('child-checkbox')) {
                                    const childId = this.getAttribute('data-id');
                                    const leafCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${childId}"]`);
                                    leafCheckboxes.forEach(leafCheckbox => {
                                        leafCheckbox.checked = isChecked;
                                    });
                                }
                                
                                // 递归处理更上一级的父级复选框
                                if (parentCheckbox.classList.contains('child-checkbox')) {
                                    const grandParentId = parentCheckbox.getAttribute('data-parent');
                                    if (grandParentId) {
                                        const grandParentCheckbox = document.querySelector(`.tree-checkbox[data-id="${grandParentId}"]`);
                                        if (grandParentCheckbox) {
                                            const uncleCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${grandParentId}"]`);
                                            const allUnclesChecked = Array.from(uncleCheckboxes).every(cb => cb.checked);
                                            grandParentCheckbox.checked = allUnclesChecked;
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            });

            // 保存权限按钮点击事件
            document.getElementById('savePermissionsBtn').addEventListener('click', function() {
                // 获取所有选中的权限
                const selectedPermissions = [];
                const checkedBoxes = document.querySelectorAll('.tree-checkbox:checked');
                checkedBoxes.forEach(checkbox => {
                    selectedPermissions.push(checkbox.getAttribute('data-id'));
                });
                
                // 这里可以发送 AJAX 请求保存权限
                console.log('选中的权限：', selectedPermissions);
                
                // 模拟保存成功
                alert('权限保存成功！');
                closeModal('assignPermissionModal');
            });
        });
    </script>
</body>
</html>